<?
//status: regmail:0 ; off: 1; onchat:2; oncpanel: 3 ; lock:4

$username= isset($_POST['username']) ? $_POST['username'] : "";
$password= isset($_POST['password']) ? $_POST['password'] : "";

if(!empty($username) || !empty($password))
{
	$password=md5($password);
	$rs=$dbsql->query("select * from ".$GLOBALS['first_table']."tbluser where cUserName='$username' and cPassword='$password'");
	if($rq=$dbsql->fetch_array($rs))
	{
		$ssid=md5(rand(4,4)._TIME.$username);
		if($rq['iStatus']==2 && !empty($rq['cSId']))
		{
			$ssid=$rq['cSId'];
		}
		$timeout=_TIME+_TIMEOUT_;
		$dbsql->query("update ".$GLOBALS['first_table']."tbluser set cSId='$ssid',iTimeOut=".$timeout.",iStatus=2 where iUserId=".$rq['iUserId']);
		
		set_Cookie(_NAMECOOKIELOGINUSER,$ssid);
		
		//send msg online to all guest:
		$h=">>>>>";
		$msg="Online >>>>>";
		$dbsql->query("update ".$GLOBALS['first_table']."tblchat set cText=concat(cText,'".$h.$username."++".$msg."$$') where iUserId=".$rq['iUserId']);
		header("location: chat.php?name=".$username."");
		exit;
	}else
	{
		$alert= "UserName or Password not match!";
	}
}

?>